package digui;
class TreeNode1 {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode1() {}
    TreeNode1(int val) { this.val = val; }
    TreeNode1(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
public class Text2 {
    //题目 : 力扣 98题 : 验证二叉搜索树
    long min = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        //递归出口
        if(root == null) {
            return true;
        }

        //左子树
        boolean left = isValidBST(root.left);
        if(left == false) return false;
        boolean tmp = false;
        if(root.val > min) {
            tmp = true;
        }
        if(tmp == false) {
            return false;
        }
        //修改 值
        min = root.val;
        boolean right = isValidBST(root.right);
        return left && tmp && right;
    }
}
